package com.magina.project.repository.base;

import com.magina.project.entity.BaseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;

import javax.transaction.Transactional;

@NoRepositoryBean
public interface SoftDeletableRepo<T extends BaseEntity,String> extends JpaRepository<T ,String> {

    @Modifying
    @Transactional
    @Query("UPDATE #{#entityName} t SET t.deleted = 1 WHERE t.id = ?1")
    void softDeleteById(String id);


//    @Modifying
//    @Transactional
//    @Query("UPDATE #{#entityName} t SET t.deleted = 1 , t.operation_flag = ?2 WHERE t.id = ?1")
//    void softDeleteAndFlagById(String id,String flag);
//
//    default void softDeleteById(String id){
//        softDeleteAndFlagById(id, (String) "D");
//    }
//
//    @Override
//    void delete(T t);

    @Modifying
    @Transactional
    @Query("UPDATE #{#entityName} t SET t.deleted = 1 WHERE t.id = ?1")
    @Override
    void deleteById(String string);
}